class User < ActiveRecord::Base
  attr_accessor :password
  validates_presence_of :account, :password, :password_confirmation, :on => :create
  validates_length_of :account, :password, :password_confirmation,:in => 6..16, :on => :create
  validates_uniqueness_of :account, :on => :create
  validates_confirmation_of :password, :on => :create

  def before_create
    self.hashed_password = Digest::MD5.hexdigest self.password
  end

  class << self
    def signin account, password
      self.find_by_account_and_hashed_password account, Digest::MD5.hexdigest(password)
    end
  end
end
